# -*- coding: utf-8 -*-
from django.core.paginator import Paginator, InvalidPage
from django.http import HttpResponse, Http404, HttpResponseRedirect, HttpResponseServerError, Http404


def paginator_parse(request, obj, item_per_page=1):

    paginator = Paginator(obj, item_per_page)

    try:
        page_number = int(request.GET['page'])
    except (KeyError, ValueError):
        page_number = 1

    try:
        current_page = paginator.page(page_number)
    except InvalidPage:
        raise Http404

    curremt_obj = current_page.object_list

    paginator_info = {
        'curremt_obj': curremt_obj,
        'show_paginator': paginator.num_pages > 1,
        'has_prev': current_page.has_previous,
        'has_next': current_page.has_next,
        'curr_page': page_number,
        'pages': paginator.num_pages,
        'prev_page': current_page.previous_page_number(),
        'next_page': current_page.next_page_number(),
        'dbprev_page': current_page.previous_page_number() - 1,
        'dbnext_page': current_page.next_page_number() + 1

    }
    return paginator_info
